<?php
class Control_Data_fetchOperationToday {

	function fetchOperationToday() {
		
		$game 		= 	MooForm::request('game');
		
		$gameLangConf = MooConfig::get('game_lang.zh_en');
		if($gameLangConf[$game]) {
			$game = $gameLangConf[$game];
		}
		
		$platform 	= 	MooForm::request('platform');			
		$channel_lang = MooConfig::get("channel_lang.{$game}");
		$getChannel = $channel	= 	MooForm::request('channel');
		
		$statistics = 	MooForm::request('statistics');			
		$startDate 	= 	MooForm::request('startTime');
		$endDate 	= 	MooForm::request('endTime');
		
		
		$fetch_operationUrl = MooConfig::get('main.url.fetch_operation_today');
		if ($channel) {
			
			if($channel_lang['zh_en'][$channel]) {
				$channel = $channel_lang['zh_en'][$channel];
			}
			
			$name = $game . "__" . $channel . "__" . $startDate . "_" . $endDate;
			$url = $fetch_operationUrl."?game=".$game."&channel=".$channel."&statistics=".$statistics."&beginDate=".$startDate."&endDate=".$endDate;
		} else if ($platform) {
			$name = $game . "__" . $platform . "__" . $startDate . "_" . $endDate;
			$url = $fetch_operationUrl."?game=".$game."&platform=".$platform."&statistics=".$statistics."&beginDate=".$startDate."&endDate=".$endDate;
		} else {
			$name = $game  . "__" . $startDate . "_" . $endDate;
			$url = $fetch_operationUrl."?game=".$game."&statistics=".$statistics."&beginDate=".$startDate."&endDate=".$endDate;
		}
		
		$rs = MooUtil::curl_send($url, null, 60);	
		$res = MooJson::decode($rs);
		
		MooObj::get('Control_Data')->setPlatformData($game);
		
		MooView::set('platform', $platform);
		MooView::set('channel', $getChannel);
		MooView::set('statistics', $statistics);
		MooView::set('startDate', $startDate);
		MooView::set('endDate', $endDate);
		
		if($res) {
			$format = array("PayRate", "userRetention2", "userRetention3","userRetention7","userRetention14","userRetention30","deviceRetention2","deviceRetention3","deviceRetention7","deviceRetention14","deviceRetention30");
			foreach($res as $key => $val) {
				foreach ($val as $k => $v) {
					if($v >= 0 && $v < 1) {
						if (in_array($k, $format)) {
							$res[$key][$k] = ($v*100)."%";
						}
					}
				}
			}
		}
		
		
		$type = MooForm::request('type');
		if($res && $type == "daochu") {
			$excelData = array();
			// 平台数据
			$dataDir = "fetchOperation";
			/**
			 * 导出数据的表头对应字段
			 */
			$keyValues = $this->OBJ->keyValuesConf;
			MooObj::get('Data')->exportExcel($name, $dataDir, $res, $keyValues);
		}
		
		
		MooView::set('data', $res);
		MooView::set('data2', $res);	
		MooView::set('data3', $res);
		MooView::set('data4', $res);
		
		MooView::render('dataViewToday');
	}
}